package com.centling.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.centling.dao.IProductDao;
import com.centling.entity.Product;
import com.centling.service.IProductService;
import com.centling.tools.ModifyDate;

@Service
public class ProductServiceImpl implements IProductService {

	@Autowired
	public IProductDao productDao;
	
	@Override
	public List<Product> getProductList() {
		
		return productDao.getProductList();
		
	}

	@Override
	public void updateProductData() {
		//获取产品List
		List<Product> productList = productDao.getProductList();
		//遍历List
		for (Product product : productList) {
			//获取产品数量数据
			Integer count = product.getCount();
			//获取产品类型入库时间
			String inwareTime = product.getInwareTime();
			//获取产品预计交货时间
			String planDeliveryTime = product.getPlanDeliveryTime();
			//修改产品数量
			product.setCount(count+5);
			//修改产品入库时间,当前时间字符串
			product.setInwareTime(ModifyDate.getDateString());
			//修改预计交货时间
			product.setPlanDeliveryTime(ModifyDate.addHalfHour());
			//如果产品数量大于300 出库-->减少库存
			if(count>300){
				product.setCount(count-250);
				productDao.updateProduct(product);
			}
			//更新产品数据
			productDao.updateProduct(product);
		}
	}

}
